<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <!-- 1 -->
    <div id="box">
      <input type="text" v-model="obj.name" @keyup.enter="enter" />
      <ane :obj="arr"></ane>
    </div>
    <!-- 内容  -->
    <template id="box1">
      <div>
        <ul>
            <li v-for="(item, index) in obj" :key="index">
                {{item.id}}--{{item.name}}--{{item.time}}
            </li>
        </ul>
     
    </div>
    </template>
    <!-- 详情 -->
    <template id="box2">
      <div></div>
    </template>
    <script>
      //第二层
      const consent = {
        template: "#box1",
        data() {
          return {
            consent: [],
          };
        },
        props: {
          obj: []  
        },
        methods: {},
       
      };
      //第一层
      new Vue({
        el: "#box",
        components: {
          ane: consent,
        },
        data() {
          return {
            obj: {
              id: 00,
              name: "",
              time: "",
            },
            arr:[]
          };
        },

        methods: {
          setTimingFn() {
            // 年月日
            const dt = new Date();
            const y = dt.getFullYear();
            const m = (dt.getMonth() + 1 + "").padStart(2, "0");
            const d = (dt.getDate() + 1 + "").padStart(2, "0");
            //  // 时分秒
            // const hh = (dt.getHours() + 1 + "").padStart(2, "0");
            // const mm = (dt.getMinutes() + 1 + "").padStart(2, "0");
            // const ss = (dt.getSeconds() + 1 + "").padStart(2, "0");
            this.obj.time = `${y}-${m}-${d}`;
          },
          enter() {
            this.setTimingFn();
            this.obj.id=this.obj.id + 1;
            console.log(this.obj);
            const list=JSON.parse(JSON.stringify(this.obj))
            this.arr.push(list)
          },
        },
      });
    </script>
  </body>
</html>
